var $;
var layer;
var table;
$(function() {
    layui.use(['table', 'layer'], function () {
        table = layui.table;
        $=layui.jquery;
        layer=layui.layer;

        //查询登录日志
        $.ajax({
            url:"/login/selUserLog",
            type:"post",
            dataType:"json",
            success:function(data){
                console.log(data);
                var tablehtml="";
                for (var i = 0; i < data.obj.length; i++){
                    var datetime=settime(data.obj[i].loginDate);
                    tablehtml+="<tr>\n" +
                        "                        <td> "+datetime+" </td>\n" +
                        "                        <td>"+data.obj[i].loginIp+"</td>\n" +
                        "                        <td>"+data.obj[i].loginLocation+"</td>\n" +
                        "                    </tr>"
                }
                $("#tbodyId").html(tablehtml);
            },
            error: function () {
                layui.msg("数据获取失败！");
            }
        });

        /*日期转换格式*/
        function settime(da){
            var date=new Date(da);
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hours=date.getHours();
            var mm=date.getMinutes();
            var s=date.getSeconds();
            return year+'-'+add(month)+'-'+add(day)+' '+add(hours)+':'+add(mm)+':'+add(s);
            //return year+'-'+month+'-'+day+' '+hours+':'+mm+':'+s;
        };
        function add(time){//给非整数添0
            return time<10?'0'+time:time;
        };
    });
});